/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.kifas.main.ui.komponen;

import com.kifas.model.xml.BarangModel;
import com.kifas.service.MasterService;
import java.awt.Component;
import java.util.List;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JComboBox;
import javax.swing.JList;
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
import org.jdesktop.beansbinding.BindingGroup;
import org.jdesktop.swingbinding.JComboBoxBinding;
import org.jdesktop.swingbinding.SwingBindings;

/**
 *
 * @author dhamarsu
 */
public class ComboBoxCustomer extends JComboBox{
    private MasterService masterService = new MasterService();
    
    public ComboBoxCustomer() {
        List<BarangModel> barangs = masterService.getBarangs();
        BindingGroup bindingGroup = new BindingGroup();
        JComboBoxBinding barangBinding =
                SwingBindings.createJComboBoxBinding(
                UpdateStrategy.READ,
                barangs,
                this);

        this.setRenderer(new DefaultListCellRenderer() {
           @Override
           public Component getListCellRendererComponent(
                   JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
               super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
               if (value instanceof BarangModel) {
                   BarangModel mec = (BarangModel)value;
                   setText(mec.getKdBarang());
               }
               return this;
           }
        });
        bindingGroup.addBinding(barangBinding);
    }

}
